package action;

import java.io.File;
import java.util.List;

import net.sf.jasperreports.engine.JasperCompileManager;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import pageModel.ProductStatistic;
import pageModel.ShopList;
import service.ShopListServiceI;

public class ProductStatisticAction extends BaseAction implements ModelDriven<ShopList>{
	 private List<ProductStatistic> myList;
	 private static final long serialVersionUID = 1L;
	 private ShopListServiceI shopListService;
	 ShopList shopList = new ShopList();
	 public ShopList getModel() {
			return shopList;
		}
	public ShopListServiceI getShopListService() {
		return shopListService;
	}
	@Autowired
	public void setShopListService(ShopListServiceI shopListService) {
		this.shopListService = shopListService;
	}
	public String execute() throws Exception {
	     myList= shopListService.jasper(shopList);
	       try {
	    	   String reportSource;
	    	   reportSource=ServletActionContext.getServletContext().getRealPath("/jasper/report3.jrxml");
	    	   File parent = new File(reportSource).getParentFile();
	    	   JasperCompileManager.compileReportToFile(reportSource, new File(parent, "report3.jasper").getAbsolutePath());          
	        } catch (Exception e) {
	            e.printStackTrace();
	            return ERROR;
	        } 
	        return SUCCESS;
	    }
	 
	    public List<ProductStatistic> getMyList() {
	        return myList;
	    }
}
